/***************************************************************************
 创建者：华磊
 开始时间：         : 2020.12.16
 copyright            : (C) 深圳市华友高科有限公司
 修改说明：（每次有修改就添加一条，带有 修改人，修改时间，修改描述）

 ***************************************************************************
 *   寄存器指令属性编辑视窗
*                                                                         *
 ***************************************************************************/
#include "registerinstructiondelegate.h"
#include <QDebug>

RegisterInstructionDelegate::RegisterInstructionDelegate(QWidget *parent):
    QObject(parent)
{
}

void RegisterInstructionDelegate::initialView()
{
    registerInstructionView->instruction = "R";

    registerInstructionView->selectRegisterType = 1;
    registerInstructionView->rIndex = "1";
    registerInstructionView->gRIndex = "1";
    registerInstructionView->pRIndex = "1";
    registerInstructionView->pLIndex = "1";
    registerInstructionView->rValue = "1";
    registerInstructionView->gRValue = "1";
    registerInstructionView->pRIValue = "PR[1]";
    registerInstructionView->pRIJValue = "1";

    registerInstructionView->iIndex = "1";
    registerInstructionView->jIndex = "1";

    registerInstructionView->plElement1 = "1";
    registerInstructionView->plElement2 = "2";
    registerInstructionView->plElement3 = "3";
    registerInstructionView->note = "";

    //registerInstructionView->updateView();
}

void RegisterInstructionDelegate::selectRInstructionSlot()
{
    registerInstructionView->selectRegisterType = EM_REGISTER_TYPE_R;
    registerInstructionView->updateView();

    qDebug() << "select R register";
}

void RegisterInstructionDelegate::selectGRInstructionSlot()
{
    registerInstructionView->selectRegisterType = EM_REGISTER_TYPE_GR;
    registerInstructionView->updateView();

    qDebug() << "select GR register";
}

void RegisterInstructionDelegate::selectPRInstructionSlot()
{
    registerInstructionView->selectRegisterType = EM_REGISTER_TYPE_PR_I;
    registerInstructionView->updateView();

    qDebug() << "select PR register";
}

void RegisterInstructionDelegate::selectPRijInstructionSlot()
{
    registerInstructionView->selectRegisterType = EM_REGISTER_TYPE_PR_IJ;
    registerInstructionView->updateView();

    qDebug() << "select PR[i, j] register";
}

void RegisterInstructionDelegate::selectPLInstructionSlot()
{
    registerInstructionView->selectRegisterType = EM_REGISTER_TYPE_PL;
    registerInstructionView->updateView();

    qDebug() << "select PL register";
}

void RegisterInstructionDelegate::clearNoteSlot()
{
    registerInstructionView->note.clear();

    qDebug("clear note");
}

void RegisterInstructionDelegate::finishEditInstructionSlot()
{
    if(EM_REGISTER_TYPE_R == registerInstructionView->selectRegisterType)
    {
        QString str = "R";
        registerInstructionView->instruction = str + "[" + registerInstructionView->rIndex + "]"
                + "=" + registerInstructionView->rValue;
    }
    else if(EM_REGISTER_TYPE_GR == registerInstructionView->selectRegisterType)
    {
        QString str = "GR";
        registerInstructionView->instruction = str + "[" + registerInstructionView->gRIndex + "]"
                + "=" + registerInstructionView->gRValue;
    }
    else if(EM_REGISTER_TYPE_PR_I == registerInstructionView->selectRegisterType)
    {
        QString str = "PR";
        registerInstructionView->instruction = str + "[" + registerInstructionView->pRIndex + "]"
                + "=" + registerInstructionView->pRIValue;
    }
    else if(EM_REGISTER_TYPE_PR_IJ == registerInstructionView->selectRegisterType)
    {
        QString str = "PR";
        registerInstructionView->instruction = str + "[" + registerInstructionView->iIndex + ","
                + registerInstructionView->jIndex + "]" + "=" + registerInstructionView->pRIJValue;
    }
    else if(EM_REGISTER_TYPE_PL == registerInstructionView->selectRegisterType)
    {
        QString str = "PL";
        registerInstructionView->instruction = str + "[" + registerInstructionView->pLIndex + "]" + "=" + "["
                + registerInstructionView->plElement1 + "," + registerInstructionView->plElement2 + "," + registerInstructionView->plElement3 + "]";
    }

    registerInstructionView->instruction = registerInstructionView->instruction + "; " + "//" + registerInstructionView->note;
}
